package template


// FindOne defines find row by id.
var FindCount = `
func (m *default{{.upperStartCamelObject}}Model) FindCount(where []WhereVars) (int64, error) {
	
	var wheres string
	var val []interface{}
	var query string

	wheres,val = FormateVars(where)
	if wheres != "" && len(val) > 0 {
		query = fmt.Sprintf("select count({{.originalPrimaryKey}}) as num from %s where %s",m.table,wheres)
	}else{
		query = fmt.Sprintf("select count({{.originalPrimaryKey}}) as num from %s ",m.table)
	}

	var resp CountNum
    {{if .withCache}}
	var err error = m.QueryRowNoCache(&resp,query,val...)
    {{else}}
    var err error = m.conn.QueryRow(&resp,query,val...)
    {{end}}

	switch err {
	case nil:
		return resp.Num, nil
	case sqlc.ErrNotFound:
		return 0, nil
	default:
		return 0, err
    }
  
}
`

// FindOneMethod defines find row method.
var FindCountMethod = `FindCount(where []WhereVars) (int64, error)`

